# -*- coding: utf-8 -*-
# @Author : zhangxuchuo
# @Date   : 2021/8/12
# @File   : Is_MicEnt_Check.py
# @E-mail : wangbaoshan@bbdservice.com

'''eof
name:是否小微企业
code:Is_MicEnt_Check
tableName:
columnName:
groups:企业通用模块
dependencies:EG_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import json
from datetime import datetime

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

def isfloat(x):
    '''
    判断x为float类型且大于等于0
    :param x:
    :return:
    '''
    try:
        if isinstance(float(x), float) and float(x)>=0:
            if str(x) in ['inf', 'infinity', 'INF', 'INFINITY', 'True']:
                return False
            else:
                return True
        else:
            return False
    except:
        return False

def FormatData(tableName):
    try:
        eg = EG_DSJ.get("data").get("R1103V3")[0].get(tableName)
        if eg in null_type_list:
            return None
        if isinstance(eg, list):
            return eg
        else:
            return None
    except:
        return None

def Is_MicEnt_Check():
    try:
        EG = FormatData('basicList')[0]
        if EG == '':
            return '缺失值'
        else:
            regCap = EG.get('regCap', '')
            if isfloat(regCap):
                if float(regCap) <= 500:
                    return 1
                else:
                    return 0
            else:
                return '缺失值' 
    except:
        return '缺失值'

# if __name__ == '__main__':
#     with open(r'C:\Users\zdr\Desktop\samples\EG_DSJ.json', encoding='utf8') as ff:
#         EG_DSJ = json.loads(ff.read())
#     result = Is_MicEnt_Check()
#     print(result)
result = Is_MicEnt_Check()